#ifndef __H_MVP_TRANSPORT_SHM_TRANSMITTER_H__
#define __H_MVP_TRANSPORT_SHM_TRANSMITTER_H__

#include <iostream>
#include "transport/transmitter/transmitter.h"
#include "transport/iox/iox_proxy.h"


namespace motovis {
namespace transport {

template <typename MessageT>
class ShmTransmitter : public Transmitter<MessageT> {
public:
    using MessagePtr = std::shared_ptr<MessageT>;
    ShmTransmitter();
    bool transmit(const std::string &channel_name,
                  const MessagePtr &msg) override;
};

template <typename MessageT>
ShmTransmitter<MessageT>::ShmTransmitter()
{
    IoxProxy::Instance();
};

template <typename MessageT>
bool ShmTransmitter<MessageT>::transmit(const std::string &channel_name,
                                        const MessagePtr &msg)
{
    char name[100] = {0};
    strncpy(name, channel_name.c_str(), channel_name.size());
    iox::popo::Publisher<MessageT> publisher({"motovis", "transport",name});
    bool result = true;
    publisher.publishResultOf([&msg](MessageT* value) {
        *value = MessageT(*msg);
    })
    .or_else([&result](auto& error) {
        // TODO: Handle error
        printf("SHM ERROR\n");
        result = false;
    });
    return result;
}

} // namespace transport
} // namespace motovis

#endif // __H_MVP_TRANSPORT_SHM_TRANSMITTER_H__